package com.xiaolong.websocket.core;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.util.Objects;

public class ChannelAfterHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        Channel channel = ctx.channel();
        // 获取存储在 Channel 中的值
        Long uid = channel.attr(NettyManager.UID).get();
        if (!Objects.isNull(uid)){
            NettyManager.removeChannel(uid);
        }
        super.channelInactive(ctx);
    }
}